#include "stdafx.h"
#include "wf_selectcontour.h"

#include "pf_selection.h"
#include "pf_snapper.h"



WF_SelectContour::WF_SelectContour(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Select Contours", container, graphicView) {

    en = NULL;
}

QAction* WF_SelectContour::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("(De-)Select Contour")
    QAction* action = new QAction(tr("(De-)Select &Contour"),  NULL);
	action->setIcon(QIcon(":/extui/selectcontour.png"));
	//action->zetStatusTip(tr("(De-)Selects connected entities"));	
    return action;
}


void WF_SelectContour::trigger() {
    if (en!=NULL) {
        if (en->isAtomic()) {
            PF_Selection s(*container, graphicView);
            s.selectContour(en);

            if (PF_DIALOGFACTORY!=NULL) {
                PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
            }
        } else {
            if (PF_DIALOGFACTORY!=NULL) {
                PF_DIALOGFACTORY->commandMessage(
                    tr("Entity must be an Atomic Entity."));
            }
        }
    } else {
        PF_DEBUG->print("PF_ActionSelectContour::trigger: Entity is NULL\n");
    }
}



void WF_SelectContour::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    } else {
        en = catchEntity(e);
        trigger();
    }
}



void WF_SelectContour::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::SelectCursor);
}

// EOF
